More changes to support a time object.
authorrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 27 Jan 2013 03:08:44 +0000 (03:08 +0000)
committerrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 27 Jan 2013 03:08:44 +0000 (03:08 +0000)
I've not gone whole hog on this; it's still pretty cowardly.  The time
class is still fundamentally a time_t (sigh) and shimmed to a subclass of
QDateTime under conditional compilation.  I'll be pulling out those props
soon.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4258 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/cetus.cc
gpsbabel/gopal.cc
gpsbabel/gpx.cc
gpsbabel/holux.cc
gpsbabel/kml.cc
gpsbabel/vitosmt.cc

index a96e36d913dfc88691007ae8f60ffcf73362937d..beca8cd306e618e4aa3d789dc3db60ae6495a975 100644 (file)
@@ -447,7 +447,6 @@ static void
 cetus_writewpt(const waypoint* wpt)
 {
   struct cetus_wpt_s* rec;
-  struct tm* tm;
   char* vdata;
   char* desc_long;
   char* desc_short;
@@ -456,6 +455,19 @@ cetus_writewpt(const waypoint* wpt)
 
   rec = (struct cetus_wpt_s*) xcalloc(sizeof(*rec)+18 + NOTESZ + DESCSZ,1);
 
+#if NEWTIME
+  QDate date(wpt->creation_time.date());
+  rec->day = date.day();
+  rec->mon = date.month();
+  be_write16(&rec->year, date.year());
+
+  QTime time(wpt->creation_time.time());
+  rec->min = time.minute();
+  rec->hour = time.hour();
+  rec->sec = time.second();
+
+#else
+  struct tm* tm;
   if (wpt->creation_time && (NULL != (tm = gmtime(&wpt->creation_time)))) {
     rec->min = tm->tm_min;
     rec->hour = tm->tm_hour;
@@ -471,6 +483,7 @@ cetus_writewpt(const waypoint* wpt)
     rec->mon = 0xff;
     be_write16(&rec->year, 0xff);
   }
+#endif
   be_write32(&rec->longitude, (unsigned int)(int)(wpt->longitude * 10000000.0));
   be_write32(&rec->latitude, (unsigned int)(wpt->latitude * 10000000.0));
   if (wpt->altitude == unknown_alt) {
index 869ae859e6a98d3fe555b4b857bf5640a0f85cc2..97aa7e0c5c9c3132a0c3105774bd5ff316c02953 100644 (file)
@@ -351,7 +351,11 @@ gopal_write_waypt(const waypoint* wpt)
   int fix=fix_unknown;
   //TICK;    TIME;   LONG;     LAT;       HEIGHT; SPEED;  UN; HDOP;     SAT
   //3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3
+#if NEWTIME
+  snprintf(tbuffer, sizeof(tbuffer), "%06d", wpt->creation_time.hms());
+#else
   strftime(tbuffer, sizeof(tbuffer), "%H%M%S", gmtime(&wpt->creation_time));
+#endif
   if (wpt->fix!=fix_unknown) {
     switch (wpt->fix) {
     case fix_none:
index 735d8bf08b8d16d1ae8a39259c325d7cc8b5d73d..10b83a78ef966b5dcc2799203f6b9a7a0c310d46 100644 (file)
@@ -855,6 +855,27 @@ gs_get_container(geocache_container t)
 time_t
 xml_parse_time(const char* cdatastr, int* microsecs)
 {
+#if NEWTIME
+  time_t rv = 0;
+  QString string_date(cdatastr);
+
+  // Lovely.  It looks like the OSM format triggers Qt Bug 18290. by
+  // leaving it ambiguous whether DST is in effect, which triggers local 
+  // time. Allegedly fixed in Qt 5.0, but trivial to work around.
+  // https://bugreports.qt-project.org/browse/QTBUG-18290
+  if (string_date.endsWith("+00:00")) {
+    string_date.replace("+00:00", "Z");
+  }
+  QDateTime dt(QDateTime::fromString(string_date, Qt::ISODate));
+
+  if (dt.isValid()) {
+    rv =  dt.toTime_t();
+    if (microsecs) {
+      *microsecs = dt.time().msec() * 1000;
+    }
+  }
+  return rv;
+#else
   int off_hr = 0;
   int off_min = 0;
   int off_sign = 1;
@@ -918,6 +939,7 @@ xml_parse_time(const char* cdatastr, int* microsecs)
   xfree(timestr);
 
   return rv;
+#endif
 }
 
 static void
index 5432c6864470d9f178e6cd681d66f299b7842773..fd1fc2381e52d02e24b1ba02587f213f4b13fed4 100644 (file)
@@ -188,7 +188,6 @@ char* mknshort(char* stIn,unsigned int sLen)
 static void holux_disp(const waypoint* wpt)
 {
   double lon,lat;
-  struct tm* tm;
   short sIndex;
   WPT* pWptHxTmp;
 
@@ -228,11 +227,21 @@ static void holux_disp(const waypoint* wpt)
   /*set the time */
   if (wpt->creation_time) {
     /* tm = gmtime(&wpt->creation_time);*/  /* I get the wrong result with gmtime ???  */
+#if NEWTIME
+    QDate date(wpt->creation_time.date());
+    QTime time(wpt->creation_time.time());
+    pWptHxTmp->time = (time.hour() * 3600) + (time.minute()* 60) + time.second();
+    pWptHxTmp->date.day = date.day();
+    pWptHxTmp->date.month = date.month();
+    pWptHxTmp->date.year = date.year();
+#else
+    struct tm* tm;
     tm = localtime(&wpt->creation_time);
     pWptHxTmp->time = (tm->tm_hour * 3600) + (tm->tm_min * 60) +tm->tm_sec;
     pWptHxTmp->date.day = tm->tm_mday;
     pWptHxTmp->date.month = tm->tm_mon + 1;
     pWptHxTmp->date.year = tm->tm_year + 1900;
+#endif
   } else {
     pWptHxTmp->time = 0;
     pWptHxTmp->date.day = 0;
index 057774df8ac2fff03b485f7860b9dc711f102b32..76ebef52af12a9b926ef82d1e5312807ba223fda 100644 (file)
@@ -1422,8 +1422,13 @@ static void kml_geocache_pr(const waypoint* waypointp)
   // Timestamp
   kml_output_timestamp(waypointp);
   if (waypointp->creation_time) {
+#if NEWTIME
+    strcpy(date_placed, 
+             qPrintable(waypointp->creation_time.toString("dd-MMM-yyyy")));
+#else
     strftime(date_placed, sizeof(date_placed),
              "%d-%b-%Y", localtime(&waypointp->creation_time));
+#endif
   } else {
     date_placed[0] = '\0';
   }
index 045cd91908c1f1c50e864782992f2c2b6124729d..72f365aec9c5ab6103812a99b078275c9709fcb8 100644 (file)
@@ -240,7 +240,6 @@ vitosmt_waypt_pr(const waypoint *waypointp)
 {
   unsigned char *      workbuffer              =0;
   size_t                       position                =0;
-  struct tm*           tmstructp               =0;
   double                       seconds                 =0;
 
   ++count;
@@ -254,7 +253,16 @@ vitosmt_waypt_pr(const waypoint *waypointp)
     WriteDouble(&workbuffer[position], waypointp->altitude);
   }
   position += sizeof(double);
-
+#if NEWTIME
+  QDate date(waypointp->creation_time.date());
+  QTime time(waypointp->creation_time.time());
+  workbuffer[position++]       = date.year()-100;
+  workbuffer[position++]       = date.month();
+  workbuffer[position++]       = date.day();
+  workbuffer[position++]       = time.hour();
+  workbuffer[position++]       = time.minute();
+#else
+  struct tm*           tmstructp               =0;
   tmstructp =  gmtime(&waypointp->creation_time);
   seconds = (double) tmstructp->tm_sec + 0.0000001*waypointp->microseconds;
 
@@ -263,6 +271,7 @@ vitosmt_waypt_pr(const waypoint *waypointp)
   workbuffer[position++]       =tmstructp->tm_mday;
   workbuffer[position++]       =tmstructp->tm_hour;
   workbuffer[position++]       =tmstructp->tm_min;
+#endif
 
   WriteDouble(&workbuffer[position], seconds);
   position += sizeof(double);